package yt.kpool.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import yt.kpool.R;
import yt.kpool.bean.BaseBean;
import yt.kpool.network.HttpUtils;
import yt.kpool.network.MyGson;
import yt.kpool.network.NetHelperNew;
import yt.kpool.util.ToastUtil;


/**
 * 修改
 * Created by Administrator on 2017/12/25.
 */

public class EditDialog extends Dialog {


    private LoadingDialog loadingDialog;
    private String title;
    private String content;
    private String hintcontent;

    private TextView tv_sure;
    private TextView tv_dis;

    private TextView tv_title;
    private EditText edit_name;


    private Context context;
    private OnSuccessListener onSuccessListener;


    /**
     * 修改dialog
     * @param context 上下文对象
     * @param title 标题
     * @param content 输入框内容
     * @param hintcontent 输入框提示语
     * @param onSuccessListener 成功回调
     */
    public EditDialog(Context context, String title, String content, String hintcontent, OnSuccessListener onSuccessListener) {
        super(context, R.style.mydialog);
        this.context = context;
        this.title = title;
        this.content = content;
        this.hintcontent = hintcontent;

        this.onSuccessListener = onSuccessListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_edit);
        setCancelable(false);
        initView();
    }

    public void initView() {
        loadingDialog = new LoadingDialog(context, 0);
        tv_sure = findViewById(R.id.tv_sure);
        tv_dis = findViewById(R.id.tv_dis);
        tv_title = findViewById(R.id.tv_title);
        edit_name = findViewById(R.id.edit_name);

        tv_title.setText(title);
        edit_name.setText(content);
        edit_name.setHint(hintcontent);

        tv_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if ("".equals(edit_name.getText().toString().trim()))
                {
                    ToastUtil.showToast(context,"输入不能为空");
                }else {
                    onSuccessListener.getResult(edit_name.getText().toString().trim());
                }


            }


        });
        tv_dis.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();

            }


        });

    }


    //点击回调
    public interface OnSuccessListener {
        void getResult(String editstring);

    }

}
